package com.rephilo.mvc.framework.controller;

import com.rephilo.mvc.framework.annotions.Autowired;
import com.rephilo.mvc.framework.annotions.Controller;
import com.rephilo.mvc.framework.annotions.RequestMapping;
import com.rephilo.mvc.framework.annotions.Security;
import com.rephilo.mvc.framework.service.IDemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author rephilo
 */
@Controller
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private IDemoService demoService;

    /**
     * 验证无权限
     *
     * @param req
     * @param resp
     * @param name
     * @return
     */
    @RequestMapping("/query")
    public String query(HttpServletRequest req, HttpServletResponse resp, String name) {
        return demoService.get(name);
    }

    /**
     * 验证admin权限
     *
     * @param req
     * @param resp
     * @param name
     * @return
     */
    @Security(roles = "admin")
    @RequestMapping("/queryAdmin")
    public String queryAdmin(HttpServletRequest req, HttpServletResponse resp, String name) {
        return demoService.get(name);
    }

    /**
     * 验证admin和Manager权限
     *
     * @param req
     * @param resp
     * @param name
     * @return
     */
    @Security(roles = "admin,manager")
    @RequestMapping("/queryManager")
    public String queryManager(HttpServletRequest req, HttpServletResponse resp, String name) {
        return demoService.get(name);
    }

    /**
     * 验证所有登录人都有权限
     *
     * @param req
     * @param resp
     * @param name
     * @return
     */
    @Security
    @RequestMapping("/queryUser")
    public String queryUser(HttpServletRequest req, HttpServletResponse resp, String name) {
        return demoService.get(name);
    }
}
